package com.weijian.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 视频信息实体类
 */
@Data
@TableName("video_info")
@Schema(description = "视频信息实体")
public class VideoInfo {
    
    @TableId(type = IdType.AUTO)
    @Schema(description = "视频ID", example = "1")
    private Long id;
    
    /**
     * 视频标题
     */
    @Schema(description = "视频标题", example = "精彩视频", requiredMode = Schema.RequiredMode.REQUIRED)
    private String title;
    
    /**
     * 文件名
     */
    @Schema(description = "文件名", example = "video.mp4", requiredMode = Schema.RequiredMode.REQUIRED)
    private String fileName;
    
    /**
     * 文件存储路径
     */
    @Schema(description = "文件存储路径", example = "videos/202401/video123.mp4")
    private String filePath;
    
    /**
     * 文件大小（字节）
     */
    @Schema(description = "文件大小（字节）", example = "10485760")
    private Long fileSize;
    
    /**
     * 视频时长（秒）
     */
    @Schema(description = "视频时长（秒）", example = "120")
    private Integer duration;
    
    /**
     * 缩略图路径
     */
    @Schema(description = "缩略图路径", example = "thumbnails/202401/thumb123.jpg")
    private String thumbnailPath;
    
    /**
     * 上传时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "上传时间", example = "2024-01-15 14:30:00")
    private LocalDateTime uploadTime;

    // 构造函数
    public VideoInfo() {
    }

    public VideoInfo(String title, String fileName, String filePath, Long fileSize) {
        this.title = title;
        this.fileName = fileName;
        this.filePath = filePath;
        this.fileSize = fileSize;
        this.duration = 0;
        this.uploadTime = LocalDateTime.now();
    }

    // Getter和Setter方法
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }

    public String getThumbnailPath() {
        return thumbnailPath;
    }

    public void setThumbnailPath(String thumbnailPath) {
        this.thumbnailPath = thumbnailPath;
    }

    public LocalDateTime getUploadTime() {
        return uploadTime;
    }

    public void setUploadTime(LocalDateTime uploadTime) {
        this.uploadTime = uploadTime;
    }

    // 工具方法
    
    /**
     * 获取文件大小（格式化显示）
     * @return 格式化后的文件大小
     */
    public String getFormattedFileSize() {
        if (fileSize == null) return "0 B";
        
        final long KB = 1024;
        final long MB = KB * 1024;
        final long GB = MB * 1024;
        
        if (fileSize < KB) return fileSize + " B";
        if (fileSize < MB) return String.format("%.1f KB", (double) fileSize / KB);
        if (fileSize < GB) return String.format("%.1f MB", (double) fileSize / MB);
        return String.format("%.1f GB", (double) fileSize / GB);
    }
    
    /**
     * 获取视频时长（格式化显示）
     * @return 格式化后的时长字符串
     */
    public String getFormattedDuration() {
        if (duration == null || duration <= 0) return "未知时长";
        
        int hours = duration / 3600;
        int minutes = (duration % 3600) / 60;
        int seconds = duration % 60;
        
        if (hours > 0) {
            return String.format("%d:%02d:%02d", hours, minutes, seconds);
        } else {
            return String.format("%d:%02d", minutes, seconds);
        }
    }

    @Override
    public String toString() {
        return "VideoInfo{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", fileName='" + fileName + '\'' +
                ", filePath='" + filePath + '\'' +
                ", fileSize=" + fileSize +
                ", duration=" + duration +
                ", thumbnailPath='" + thumbnailPath + '\'' +
                ", uploadTime=" + uploadTime +
                '}';
    }
}